package com.kksoft.readcm.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.kksoft.readcm.e.b;
import com.kksoft.readcm.pro.R;
import com.kksoft.readcm.views.OnSizeChangedListener;
import com.kksoft.readcm.views.ResizeDetectImageView;
import java.util.Iterator;
import java.util.Set;

public class SplashActivity extends RilAppActivity
{
  private ResizeDetectImageView ResizeDImageView;   //old a
  private ImageView imageLogo = null;
  private ImageView imageTitle = null;
  private LinearLayout linearLayout = null;
  private Button btnLogin = null;
  private Button btnNew = null;
  private boolean g = false;
  private boolean h = false;

  private void a(boolean paramBoolean)
  {
    if (!paramBoolean)
      this.btnLogin.setShadowLayer(1.0F, 0.0F, -0.5F, -16777216);
    else
      this.btnLogin.setShadowLayer(0.0F, 0.0F, 0.0F, 0);
  }

  protected final int b_()
  {
    return 3;
  }

  protected final boolean d()
  {
    return false;
  }

  protected final Drawable d_()
  {
    return getResources().getDrawable(2130837619);
  }

  public void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    getWindow().setFormat(1);
  }

  public void onCreate(Bundle savedInstanceState)
  {
	  
    Intent localIntent = getIntent();
    if ((localIntent != null) && ((localIntent.getFlags() & Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0x400000) && (App.getSharedPreferences().getBoolean("allowLaunchFix", true)))
    {
      this.h = true;
      finish();
      overridePendingTransition(0, 0);
    }
    super.onCreate(savedInstanceState);
    this.r = true;
    
    this.ResizeDImageView=(ResizeDetectImageView)findViewById(R.id.splash_bg);
    this.ResizeDImageView.setBackgroundDrawable(d(false));
    
    ResizeDImageView.setOnSizeChanged(new OnSizeChangedListener(){ 
		@Override
		public void SizeChanged(View arg0) {
			// TODO Auto-generated method stub
			if(!a(SplashActivity.this) && arg0.getHeight() > 0)
		         SplashActivity.c(SplashActivity.this);
		}
	});

    this.imageLogo = (ImageView)findViewById(R.id.splash_logo);
    this.imageTitle = (ImageView)findViewById(R.id.splash_titles);
    this.linearLayout = (LinearLayout)findViewById(R.id.splash_buttons);
    this.btnLogin = (Button)findViewById(R.id.splash_login);
    
    this.btnLogin.setOnClickListener(new OnClickListener(){ 
		public void onClick(View arg0) {
		    Intent it = new Intent(SplashActivity.this, LoginActivity.class);
		    it.putExtra("com.kksoft.readcm.pro.loginType", 2);
		    startActivity(it);
        }
	});
    
    this.btnLogin.setOnFocusChangeListener(new OnFocusChangeListener(){

		@Override
		public void onFocusChange(View v, boolean hasFocus) {
			// TODO Auto-generated method stub
			SplashActivity.a(SplashActivity.this, hasFocus);
		}
    		
    });
    a(this.btnLogin.hasFocus());
    
    this.btnNew = (Button)findViewById(R.id.splash_create);
    this.btnNew.setOnClickListener(new OnClickListener(){ 
		public void onClick(View arg0) {
			Intent it = new Intent(SplashActivity.this, LoginActivity.class);
		    it.putExtra("com.kksoft.readcm.pro.loginType", 1);
		    startActivity(it);
        }
	});
  }

  protected void onDestroy()
  {
	  super.onDestroy();  
	  try
	  {
	  Object obj;
      int k;
      String s1;
      obj = getIntent();
      k = ((Intent) (obj)).getFlags();
      obj = ((Intent) (obj)).getCategories();
  	  Iterator iterator = ((Set) (obj)).iterator();
	  while(iterator.next() != null)
	  {
		  //String s2 = s1;
          //String s3 = (new StringBuilder("Failed launch fix with flags: ")).append(k).append(" and categories: ").append(s2).toString();
          //throw new b(s3);
          //b b1;
         // b1;
          //boolean flag = App.h().edit().putBoolean("allowLaunchFix", false).commit();
          //App.a(b1, true);
	  }
	  }
	  catch(Exception e)
	  {
		  //String s5 = String.valueOf(s1);
	       // s1 = (new StringBuilder(s5)).append(s4).toString();
	  }
  }

  public boolean onPrepareOptionsMenu(Menu paramMenu)
  {
    paramMenu.setGroupVisible(-1, false);
    paramMenu.setGroupVisible(-1, true);
    paramMenu.setGroupVisible(-1, false);
    return true;
  }

  public void onResume()
  {
    super.onResume();
  }

  public boolean onSearchRequested()
  {
    return false;
  }

  protected final int getLayoutID()
  {
    return R.layout.activity_splash;
  }

  static void a(SplashActivity splashactivity, boolean flag)
  {
      splashactivity.a(flag);
  }

  static boolean a(SplashActivity splashactivity)
  {
      return splashactivity.g;
  }

//  static ResizeDetectImageView imageLogo(SplashActivity splashactivity)
//  {
//      return splashactivity.ResizeDImageView;
//  }

  static void c(SplashActivity splashactivity)
  {
      splashactivity.g = true;
      Rect rect = new Rect();
      splashactivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
      int k = rect.top / 2;
      Animation animation = AnimationUtils.loadAnimation(splashactivity, 0x10a0000);
      animation.setDuration(700L);
      animation.setFillAfter(true);
      int l = 0 - k;
      int i1 = (int)splashactivity.a(94F);
      int j1 = l - i1;
      float f1 = 0 - k;
      float f2 = j1;
      TranslateAnimation translateanimation = new TranslateAnimation(0F, 0F, f1, f2);
      translateanimation.setDuration(700L);
      translateanimation.setFillAfter(true);
      translateanimation.setStartOffset(300L);
      translateanimation.setInterpolator(splashactivity, 0x10a0004);
      Animation animation1 = AnimationUtils.loadAnimation(splashactivity, 0x10a0000);
      animation1.setDuration(700L);
      animation1.setFillAfter(true);
      animation1.setStartOffset(850L);
      splashactivity.ResizeDImageView.setVisibility(0);
      splashactivity.imageLogo.setVisibility(0);
      splashactivity.imageTitle.setVisibility(0);
      splashactivity.linearLayout.setVisibility(0);
      splashactivity.getWindow().setBackgroundDrawableResource(0x7f02000a);
      splashactivity.ResizeDImageView.startAnimation(animation);
      splashactivity.imageLogo.startAnimation(translateanimation);
      splashactivity.imageTitle.startAnimation(animation1);
      splashactivity.linearLayout.startAnimation(animation1);
  }
}